package com.ykq.controller;

import com.ykq.annotation.MethodAnnotation;
import com.ykq.service.EmpInfoService;
import com.ykq.vo.EmpSearchVo;
import com.ykq.vo.LoginVo;
import com.ykq.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * @program: qy174-mrcai
 * @description:
 * @author: 闫克起
 * @create: 2024-06-04 11:41
 **/
@RestController
@RequestMapping("/empinfo")
public class EmpInfoController {

    @Autowired
    private EmpInfoService empInfoService;


    @PostMapping("/login")
    public R login(@RequestBody LoginVo loginVo) {
        return empInfoService.findByNameAndPwd(loginVo.getUsername(), loginVo.getPassword());
    }

    @Autowired
    private HttpSession session;
    @GetMapping("/info")
    @MethodAnnotation("获取当前用户信息")
    public R info() {
        Object empinfo = session.getAttribute("empinfo");
        if (empinfo == null) {
            return new R(5000, "登录失效", null);
        } else {
            return new R(2000, "获取用户信息成功", empinfo);
        }
    }

    @GetMapping("/logout")
    @MethodAnnotation("退出")
    public R logout() {
        session.removeAttribute("empinfo");
        return new R(2000, "退出成功", null);
    }

    @PostMapping("/list")
    @MethodAnnotation("分页条件查询所有员工")
    public R list(Integer current,Integer pageSize,@RequestBody EmpSearchVo empSearchVo){
       return empInfoService.selectByConditPage(current,pageSize,empSearchVo);
    }
}
